<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
  <div id="app">
  </div>
  <script>


    var cache = {
      add(key, value) {
        localStorage.setItem(key, value)
      },
      del(key) {

      }
    }


    // var MyPlugin = {
    //   //自定义插件，必须要实现install的方法
    //   install(v) {
    //     v.prototype.$cache= cache;
    //   }
    // }

    Vue.use({
      install(v) {
        //自定义插件，必须要实现install的方法
        v.prototype.$cache = cache;
      }
    })

    var vm = new Vue({
      el: "#app",
      data: {},
      mounted() {
        let tmp = this;
        this.$cache.add()
      }
    })
  </script>
</body>

</html>